package b2.widget.room
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.*;
	import b2.util.BFont;
	import b2.widget.*;
	import b2.widget.tank.*;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;

	public class MatchPlayerItem extends Sprite
	{
		private const RANK_COLOR:Array = [0xFF0000, 0xA0A000, 0x00A000, 0x000000];
		private const RANK_NAME:Array = ["st", "nd", "rd", ""];
		public var rankingText:TextField;
		public var playerNameText:TextField;
		public var matchHonourText:TextField;
		public var fightPointText:TextField;
		public var honourAwardText:TextField;
		public var oilAwardText:TextField;
		
		public function MatchPlayerItem()
		{
			super();
			//背景框
			var RankingItemBgr:Class = ResourceHelper.getInstance().getClassByName("RankingItemBgr");
			var rankingItemBgr:Sprite = new RankingItemBgr();
			rankingItemBgr.alpha = 0.8;
			addChild(rankingItemBgr);
			//排名
			rankingText = new TextField();
			rankingText.selectable = false;
        	rankingText.autoSize = TextFieldAutoSize.CENTER;
			rankingText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			rankingText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			rankingText.x = 22;
			rankingText.y = 2;
			addChild(rankingText);
			//用户名字
			playerNameText = new TextField();
			playerNameText.selectable = false;
        	playerNameText.autoSize = TextFieldAutoSize.CENTER;
			playerNameText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			playerNameText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			playerNameText.x = 85;
			playerNameText.y = 2;
			addChild(playerNameText);
			//数值
			matchHonourText = new TextField();
			matchHonourText.selectable = false;
        	matchHonourText.autoSize = TextFieldAutoSize.CENTER;
			matchHonourText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			matchHonourText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			matchHonourText.x = 154;
			matchHonourText.y = 2;
			addChild(matchHonourText);
			//战力
			fightPointText = new TextField();
			fightPointText.selectable = false;
        	fightPointText.autoSize = TextFieldAutoSize.CENTER;
			fightPointText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			fightPointText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			fightPointText.x = 215;
			fightPointText.y = 2;
			addChild(fightPointText);
			//荣誉奖励
			honourAwardText = new TextField();
			honourAwardText.selectable = false;
        	honourAwardText.autoSize = TextFieldAutoSize.CENTER;
			honourAwardText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			honourAwardText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			honourAwardText.x = 275;
			honourAwardText.y = 2;
			addChild(honourAwardText);
			//石油奖励
			oilAwardText = new TextField();
			oilAwardText.selectable = false;
        	oilAwardText.autoSize = TextFieldAutoSize.CENTER;
			oilAwardText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			oilAwardText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			oilAwardText.x = 350;
			oilAwardText.y = 2;
			addChild(oilAwardText);
			
			this.addEventListener(MouseEvent.CLICK, showTankInfo);
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		public function getLevel(exp:int):Array
		{
			var level:int = 0;
			while (level < Config.levelConfigs.length && exp >= Config.levelConfigs[level].experience)
			{
				exp -= Config.levelConfigs[level].experience;
				level++;
			}
			var rate:int = Math.floor(exp * 100 / Config.levelConfigs[level].experience);
			return [level + 1, rate];
		}
		
		public function clear():void
		{
			rankingText.text = "";
			playerNameText.text = "";
			matchHonourText.text = "";
			fightPointText.text = "";
			honourAwardText.text = "";
			oilAwardText.text = "";
		}
		
		private function showTankInfo(event:MouseEvent):void
		{
//			ServerHelper.getInstance().getPlayerInfo(this.rankingInfo.playerId);
//			ServerHelper.getInstance().addEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
		}
		
		private function onShowTankInfoComplete(event:ServerEvent):void
		{
//			ServerHelper.getInstance().removeEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
//			TankDialog.getInstance().fresh(this.rankingInfo.tankId);
//			WidgetManager.getInstance().popOut([TankDialog.getInstance()], false, true);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
		}
	}
}